/*
 * @Author: hexudong 1264275442@qq.com
 * @Date: 2023-04-11 17:58:25
 * @LastEditors: hexudong 1264275442@qq.com
 * @LastEditTime: 2023-04-25 16:12:11
 * @FilePath: /worker_supervision_oa/src/components/BorrowDetail/processModal.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Form, Radio, Input, Button, message } from 'antd';
import FileUpload from '@/components/FileUpload';
import { handleFileid } from '@/utils/utils';
import React, { } from 'react';
import { bankRepayLoanCheck } from '@/services/public'

const FormItem = Form.Item;
const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },
};

interface ProcessModalProps {
    detailMessage: any;
    onSubmit: () => void;
}
const ProcessModal: React.FC<ProcessModalProps> = ({ detailMessage, onSubmit }) => {
    const [form] = Form.useForm();
    const checkValue = Form.useWatch('check', form);
    const tailLayout = {
        wrapperCol: { offset: 8, span: 8 },
    };
    const reconfirm = async () => {
        try {
            const fieldsValue: any = await form.validateFields();
            let params = {}
            params = {
                id: detailMessage.id,
                check: fieldsValue.check,
                remark: fieldsValue.remark,
                checkFileId: (fieldsValue.check==1&&fieldsValue.checkFileId) ? handleFileid(fieldsValue.checkFileId) : ''
            }
            
            let res = await bankRepayLoanCheck(params)
            if (res && res.success) {
                // history.goBack()
                onSubmit();
            }  else  {
                message.error(res.errMsg || '');
            }
            console.log(res,'123');
        } catch (error) {

        }
    }
    return (
        <>
            <Form {...formItemLayout} name="save_project" form={form}>
                <FormItem
                    label="审核意见"
                    name="check"
                    initialValue={1}
                    rules={[{ required: true, message: '请选择审核意见！' }]}
                >
                    <Radio.Group>
                        <Radio value={1}>已收到还款</Radio>
                        <Radio value={0}>未收到还款</Radio>
                    </Radio.Group>
                </FormItem>
                {
                    checkValue == 1 && (
                        <FormItem
                            label="上传凭证"
                            name="checkFileId"
                            initialValue={[]}
                            rules={[{ required: true, message: '请选择上传凭证！' }]}
                        >
                            <FileUpload ossEnum="PROJECT" multiple={true} max={6} type="image/*,.pdf,.doc,.docx" />
                        </FormItem>
                    )
                }

                <FormItem label="审核备注" name="remark" initialValue="" >
                    <Input.TextArea showCount maxLength={100} />
                </FormItem>
                <FormItem {...tailLayout} style={{ textAlign: 'center' }}>
                    <Button type="primary" onClick={() => reconfirm()}>确定</Button>
                </FormItem>
            </Form>
        </>
    );
};

export default ProcessModal;